package com.agil.photoalbum.db.entities;

import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;

import com.agil.photoalbum.db.util.SessionManager;

public class User implements java.io.Serializable {

	private long userId;
	private String userName;
	private String userPass;
	private String FName;
	private String LName;
	private String email;
	private Set<Comment> comments = new HashSet<Comment>(0);
	private Set<Role> roles = new HashSet<Role>(0);
	private Set<Category> categories = new HashSet<Category>(0);

	public User() {
	}

	public User(long userId, String userName, String userPass) {
		this.userId = userId;
		this.userName = userName;
		this.userPass = userPass;
	}
        
        public User( String userName, String userPass, String FName,
                String LName, String email) {
           // this.userId = userId;
            this.userName = userName;
            this.userPass = userPass;
            this.FName = FName; 
            this.LName = LName; 
            this.email = email;
        }

	public User(long userId, String userName, String userPass, String FName,
			String LName, String email, Set<Comment> commentses, Set<Role> roleses,
			Set<Category> categorieses) {
		this.userId = userId;
		this.userName = userName;
		this.userPass = userPass;
		this.FName = FName;
		this.LName = LName;
		this.comments = commentses;
		this.roles = roleses;
		this.categories = categorieses;
		this.email = email;
	}

	public User(User user) {
		this(user.getUserId(), user.getUserName(), user.getUserPass(), user
				.getFName(), user.getLName(), user.getEmail(), user.getComments(), user
				.getRoles(), user.getCategories());
	}

	public boolean isAdmin() {
		SessionManager.openSession();
		Set<Role> roles = this.getRoles();
		for(Role r: roles)
		{
			if(r.getRoleType().equalsIgnoreCase("admin"))
			{
				SessionManager.closeSession();
				return true;
			}
		}
		SessionManager.closeSession();
		return false;
	}
	
	public long getUserId() {
		return this.userId;
	}

	public void setUserId(long userId) {
		this.userId = userId;
	}

	public String getUserName() {
		return this.userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getUserPass() {
		return this.userPass;
	}

	public void setUserPass(String userPass) {
		this.userPass = userPass;
	}

	public String getFName() {
		return this.FName;
	}

	public void setFName(String FName) {
		this.FName = FName;
	}

	public String getLName() {
		return this.LName;
	}

	public void setLName(String LName) {
		this.LName = LName;
	}

	public Set<Comment> getComments() {
		return this.comments;
	}

	public void setComments(Set<Comment> commentses) {
		this.comments = commentses;
	}

	public Set<Role> getRoles() {
		return this.roles;
	}

	public void setRoles(Set<Role> roleses) {
		this.roles = roleses;
	}

	public Set<Category> getCategories() {
		return this.categories;
	}

	public void setCategories(Set<Category> categorieses) {
		this.categories = categorieses;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

}
